<?php

namespace App\Admin\Controllers;

use App\Admin\Model\Cash;

use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;

class CashController extends Controller
{
    use ModelForm;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header('提现');
            $content->description('提现列表');

            $content->body($this->grid());
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {

            $content->header('header');
            $content->description('description');

            $content->body($this->form()->edit($id));
        });
    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {

            $content->header('header');
            $content->description('description');

            $content->body($this->form());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(Cash::class, function (Grid $grid) {
            $grid->filter(function ($filter) {
                $filter->like('uid', 'UID');
                $filter->like('owner_name', '姓名');
                $filter->like('owner_mobile', '手机号');
            });
            
            $grid->cid('ID')->sortable();
            $grid->uid('用户ID')->sortable();
            $grid->owner_id('房东ID')->sortable();
            $grid->owner_name('姓名')->sortable();
            $grid->owner_mobile('手机号')->sortable();
            $grid->bid('银行卡号')->sortable();
            $grid->bank_name('开户支行名称')->sortable();
            $grid->bank_card('开户银行账号')->sortable();
            $grid->card('卡号后四位')->sortable();
            $grid->cash_amount('提现金额')->sortable();
            $grid->status('状态')->display(function ($status) {
                switch ($status) {
                    case 0:
                        return '正在申请中';
                        break;
                    case 1:
                        return '申请成功';
                        break;
                    case 2:
                        return '申请失败';
                        break;
                    default:
                        return '不知道';
                        break;
                }
            });
            $grid->req_sn('交易流水号')->sortable();
            $grid->bank_code('银行代码')->sortable();
            $grid->source('提现来源')->display(function($source){
                switch ($source) {
                    case 1:
                        return '>>>>';
                        break;
                    case 2:
                        return '推广收入提现';
                        break;
                    default:
                        return '不知道';
                        break;
                }
            });
            
            $grid->created_at('提现时间');
            // $grid->updated_at();
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Admin::form(Cash::class, function (Form $form) {

            $form->display('cid', 'ID');

            $form->display('created_at', 'Created At');
            $form->display('updated_at', 'Updated At');
        });
    }
}
